﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace API.Models.Repository
{
    public class Suppliers_Repository : GenericRepository<PartnerDbContext, WH_COMPANIES>
    {
        public override IQueryable<WH_COMPANIES> Find(System.Linq.Expressions.Expression<Func<WH_COMPANIES, bool>> predicate)
        {
            IQueryable<WH_COMPANIES> query = _entities.WH_COMPANIES;

            if (predicate != null)
                query = query.Where(predicate);

            if (session != null)
            {
                query = query
                    .Where(r => r.OWNER_GUID == session.COMPANY_GUID)
                    .AsQueryable();
            }

            return query;
        }
        
        public override void Add(WH_COMPANIES entity)
        {
            entity.OWNER_GUID = this.session.COMPANY_GUID;
            base.InsertOrUpdate(entity);
        }

        public override void Edit(WH_COMPANIES entity)
        {
            entity.OWNER_GUID = this.session.COMPANY_GUID;
            base.Edit(entity);
        }
    }
}